﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using NUnit.Framework;

using System.Net;
using System.Net.DnsToolkit.Util;
using System.Net.DnsToolkit.Packet;
using System.Net.DnsToolkit.Packet.Records;
using System.Net.DnsToolkit.Serializer;
using System.Net.DnsToolkit.Serializer.Stream.Compression;
using System.Net.DnsToolkit.Packet.Busy;
using System.Net.DnsToolkit.Packet.Busy.Records;

namespace System.Net.DnsToolkit.TestUnit.Helper.Serializer {
    [TestFixture]
    public class DnsCompressionTest {

        #region CreateDomain
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestCreateDomainNull() {
            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(null, domains);
        }

        [Test]
        public void TestCreateDomainEmpty() {
            IMessage message = new Message();
            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);
            Assert.AreEqual(0, domains.Count());
        }

        [Test]
        public void TestCreateDomain1() {

            IMessage message = new Message() {
                Header = new Header(),
                Questions = new List<IQuestion>() {
                    new Question() {
                        QName = new DomainName() { Name = "www.domn.tl." },
                        QType = QTypeEnum.A,
                        QClass = QClassEnum.IN
                    }
                }
            };

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(1, domains.Count());
            Assert.AreEqual("www.domn.tl.", domains.First().Name);


        }

        [Test]
        public void TestCreateDomain2() {

            IMessage message = new Message() {
                Header = new Header(),
                Questions = new List<IQuestion>() {
                    new Question() {
                        QName = new DomainName() { Name = "www.domn.tl." },
                        QType = QTypeEnum.A,
                        QClass = QClassEnum.IN
                    }
                },
                Answers = new List<IRR>() {
                    new RR() {
                        Name = new DomainName() { Name = "www.domn.tl." },
                        Ttl = 0,
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.A,
                        RDLength = 4,
                        RData = new RecordA() {
                            Address = IPAddress.Parse("1.2.3.4")
                        }
                        
                    }
                }
            };

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(2, domains.Count());
            Assert.AreEqual("www.domn.tl.", domains.First().Name);
            Assert.AreEqual("www.domn.tl.", domains.ElementAt(1).Name);


        }

        [Test]
        public void TestCreateDomain3() {

            IMessage message = new Message() {
                Header = new Header(),
                Questions = new List<IQuestion>() {
                    new Question() {
                        QName = new DomainName() { Name = "domn.tl." }, 
                        QType = QTypeEnum.MX,
                        QClass = QClassEnum.IN
                    }
                },
                Answers = new List<IRR>() {
                    new RR() {
                        Name = new DomainName() { Name = "domn.tl." }, 
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.MX ,
                        RData = new RecordMX() {
                            EXCHANGE = new DomainName() { Name = "mx1.domn.tl." },
                            PREFERENCE = 10
                        }
                    },
                    new RR() {
                        Name = new DomainName() { Name = "domn.tl." }, 
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.MX ,
                        RData = new RecordMX() {
                            EXCHANGE = new DomainName() { Name = "mx2.domn.tl." },
                            PREFERENCE = 20
                        }
                    }
                },
                Authorities = new List<IRR>() {
                    new RR() {
                        Name = new DomainName() { Name = "domn.tl." }, 
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.NS,
                        RData = new RecordNS() {
                            NSDNAME = new DomainName() { Name = "ns01.domn.tl." }
                        }
                    },
                    new RR() {
                        Name = new DomainName() { Name = "domn.tl." }, 
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.NS,
                        RData = new RecordNS() {
                            NSDNAME = new DomainName() { Name = "ns02.domn.tl." }
                        }
                    },
                },
                Additionals = new List<IRR>() {
                    new RR() {
                        Name = new DomainName() { Name = "mx1.domn.tl." },
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.A,
                        RDLength = 4,
                        RData = new RecordA() {
                            Address = IPAddress.Parse("1.2.3.4")
                        }
                    },
                    new RR() {
                        Name = new DomainName() { Name = "mx2.domn.tl." },
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.A,
                        RDLength = 4,
                        RData = new RecordA() {
                            Address = IPAddress.Parse("1.2.3.4")
                        }
                    },
                    new RR() {
                        Name = new DomainName() { Name = "ns01.domn.tl." },
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.A,
                        RDLength = 4,
                        RData = new RecordA() {
                            Address = IPAddress.Parse("1.2.3.4")
                        }
                    },
                    new RR() {
                        Name = new DomainName() { Name = "ns02.domn.tl." },
                        RRClass = QClassEnum.IN,
                        RRType = QTypeEnum.A,
                        RDLength = 4,
                        RData = new RecordA() {
                            Address = IPAddress.Parse("1.2.3.4")
                        }
                    }
                }
            };

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(13, domains.Count());
            Assert.AreEqual("domn.tl.", domains.ElementAt(0).Name);
            Assert.AreEqual("mx1.domn.tl.", domains.ElementAt(1).Name);
            Assert.AreEqual("mx2.domn.tl.", domains.ElementAt(2).Name);
            Assert.AreEqual("ns01.domn.tl.", domains.ElementAt(3).Name);
            Assert.AreEqual("ns02.domn.tl.", domains.ElementAt(4).Name);
            Assert.AreEqual("domn.tl.", domains.ElementAt(5).Name);
            Assert.AreEqual("domn.tl.", domains.ElementAt(6).Name);
            Assert.AreEqual("domn.tl.", domains.ElementAt(7).Name);
            Assert.AreEqual("domn.tl.", domains.ElementAt(8).Name);
            Assert.AreEqual("ns01.domn.tl.", domains.ElementAt(9).Name);
            Assert.AreEqual("ns02.domn.tl.", domains.ElementAt(10).Name);
            Assert.AreEqual("mx1.domn.tl.", domains.ElementAt(11).Name);
            Assert.AreEqual("mx2.domn.tl.", domains.ElementAt(12).Name);


        }


        [Test]
        public void TestCreateDomain4() {

            string expected = "0003818000010001000000000377777704646f6d6e02746c00000100010377777704646f6d6e02746c000001000100015180000401020304";
            IMessage message = PacketHelper.Read(expected);

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(2, domains.Count());
            Assert.AreEqual("www.domn.tl.", domains.ElementAt(0).Name);
            Assert.AreEqual("www.domn.tl.", domains.ElementAt(1).Name);


        }


        [Test]
        public void TestCreateDomain5() {

            string expected = "0002818000010002000000020370727602746C0000020001c00c0002000100014f3a0007046e733031c00cc00c0002000100014f3a0007046e733032c00cc0240001000100014f3a000401020a0fc0370001000100014bb5000401020aa1";
            IMessage message = PacketHelper.Read(expected);

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(7, domains.Count());
            Assert.AreEqual("prv.tl.", domains.ElementAt(0).Name);
            Assert.AreEqual("ns01.prv.tl.", domains.ElementAt(1).Name);
            Assert.AreEqual("ns02.prv.tl.", domains.ElementAt(2).Name);
            Assert.AreEqual("prv.tl.", domains.ElementAt(3).Name);
            Assert.AreEqual("prv.tl.", domains.ElementAt(4).Name);
            Assert.AreEqual("ns01.prv.tl.", domains.ElementAt(5).Name);
            Assert.AreEqual("ns02.prv.tl.", domains.ElementAt(6).Name);


        }

        [Test]
        public void TestCreateDomain6() {

            string expected = "0003818000010005000400040377777706676f6f676c6503636f6d0000010001c00c000500010007efb7000803777777016cc010c02c00010001000002f00004d1558193c02c00010001000002f00004d1558163c02c00010001000002f00004d1558167c02c00010001000002f00004d1558168c010000200010002a2bf0006036e7333c010c010000200010002a2bf0006036e7331c010c010000200010002a2bf0006036e7334c010c010000200010002a2bf0006036e7332c010c0800001000100028b940004d8ef240ac0920001000100028b940004d8ef200ac0a40001000100028b940004d8ef260ac0b6000100010004064d0004d8ef220a";
            IMessage message = PacketHelper.Read(expected);

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(19, domains.Count());
            Assert.AreEqual("www.google.com.", domains.ElementAt(0).Name);
            Assert.AreEqual("google.com.", domains.ElementAt(1).Name);
            Assert.AreEqual("google.com.", domains.ElementAt(2).Name);
            Assert.AreEqual("google.com.", domains.ElementAt(3).Name);
            Assert.AreEqual("google.com.", domains.ElementAt(4).Name);
            Assert.AreEqual("ns3.google.com.", domains.ElementAt(5).Name);
            Assert.AreEqual("ns1.google.com.", domains.ElementAt(6).Name);
            Assert.AreEqual("ns4.google.com.", domains.ElementAt(7).Name);
            Assert.AreEqual("ns2.google.com.", domains.ElementAt(8).Name);
            Assert.AreEqual("www.google.com.", domains.ElementAt(9).Name);
            Assert.AreEqual("www.l.google.com.", domains.ElementAt(10).Name);
            Assert.AreEqual("www.l.google.com.", domains.ElementAt(11).Name);
            Assert.AreEqual("www.l.google.com.", domains.ElementAt(12).Name);
            Assert.AreEqual("www.l.google.com.", domains.ElementAt(13).Name);
            Assert.AreEqual("ns3.google.com.", domains.ElementAt(14).Name);
            Assert.AreEqual("ns1.google.com.", domains.ElementAt(15).Name);
            Assert.AreEqual("ns4.google.com.", domains.ElementAt(16).Name);
            Assert.AreEqual("ns2.google.com.", domains.ElementAt(17).Name);
            Assert.AreEqual("www.l.google.com.", domains.ElementAt(18).Name);


        }

        [Test]
        public void TestCreateDomain7() {

            string expected = "f8de81800001001200030003036170690a7261706964736861726503636f6d0000010001c00c00010001000003840004c37a8323c00c00010001000003840004c37a8324c00c00010001000003840004c37a8325c00c00010001000003840004c37a8326c00c00010001000003840004c37a8327c00c00010001000003840004c37a8328c00c00010001000003840004c37a8317c00c00010001000003840004c37a8318c00c00010001000003840004c37a8319c00c00010001000003840004c37a831ac00c00010001000003840004c37a831bc00c00010001000003840004c37a831cc00c00010001000003840004c37a831dc00c00010001000003840004c37a831ec00c00010001000003840004c37a831fc00c00010001000003840004c37a8320c00c00010001000003840004c37a8321c00c00010001000003840004c37a8322c01000020001000003840006036e7333c010c01000020001000003840006036e7331c010c01000020001000003840006036e7332c010c15000010001000003840004528127cdc16200010001000003840004c37a83fac1740001000100000000000450ef97cd";
            IMessage message = PacketHelper.Read(expected);

            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);

            Assert.AreEqual(28, domains.Count());
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(0).Name);
            Assert.AreEqual("rapidshare.com.", domains.ElementAt(1).Name);
            Assert.AreEqual("rapidshare.com.", domains.ElementAt(2).Name);
            Assert.AreEqual("rapidshare.com.", domains.ElementAt(3).Name);
            Assert.AreEqual("ns3.rapidshare.com.", domains.ElementAt(4).Name);
            Assert.AreEqual("ns1.rapidshare.com.", domains.ElementAt(5).Name);
            Assert.AreEqual("ns2.rapidshare.com.", domains.ElementAt(6).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(7).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(8).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(9).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(11).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(12).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(13).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(14).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(15).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(16).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(17).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(18).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(19).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(20).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(21).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(22).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(23).Name);
            Assert.AreEqual("api.rapidshare.com.", domains.ElementAt(24).Name);
            Assert.AreEqual("ns3.rapidshare.com.", domains.ElementAt(25).Name);
            Assert.AreEqual("ns1.rapidshare.com.", domains.ElementAt(26).Name);
            Assert.AreEqual("ns2.rapidshare.com.", domains.ElementAt(27).Name);



        }



        #endregion

        #region CreateSubDomain

        [Test]
        public void TestCreateSubDomain1() {

            DomainName domain = new DomainName() {
                Name = "domain.tld."
            };
            DomainName host = new DomainName() {
                Name = "host.domain.tld."
            };
            DomainName sub = new DomainName() {
                Name = "sub.domain.tld."
            };
            DomainName host1 = new DomainName() {
                Name = "host1.sub.domain.tld."
            };
            DomainName host2 = new DomainName() {
                Name = "host2.sub.domain.tld."
            };
            DomainName domain2 = new DomainName() {
                Name = "domain2.tld."
            };

            var source = new List<IDomainName>() { domain, host, sub, host1, host2, domain2 };

            IDictionary<IDomainName, SubDomainName> subdomains = CompressionHelper.CreateSubDomain(source);

            Assert.AreEqual("domain.", subdomains[domain].Name);
            Assert.AreEqual("host.", subdomains[host].Name);
            Assert.AreEqual("sub.", subdomains[sub].Name);
            Assert.AreEqual("host1.", subdomains[host1].Name);
            Assert.AreEqual("host2.", subdomains[host2].Name);
            Assert.AreEqual("domain2.", subdomains[domain2].Name);

            Assert.AreEqual("tld.", subdomains[domain].Right.Name);
            Assert.AreEqual("tld.", subdomains[domain2].Right.Name);
            Assert.AreEqual(subdomains[domain].Right.Name, subdomains[domain2].Right.Name);

            Assert.IsNull(subdomains[domain].Right.Right);
            Assert.IsNull(subdomains[domain2].Right.Right);

            Assert.AreEqual(subdomains[host].Right, subdomains[domain]);
            Assert.AreEqual(subdomains[sub].Right, subdomains[domain]);
            Assert.AreEqual(subdomains[host1].Right, subdomains[sub]);
            Assert.AreEqual(subdomains[host2].Right, subdomains[sub]);


        }

        [Test]
        public void TestCreateSubDomain2() {

            DomainName domain = new DomainName() {
                Name = "domain.com."
            };
            DomainName domain2 = new DomainName() {
                Name = "domain.com.tld2."
            };
            DomainName sub = new DomainName() {
                Name = "sub.domain.com."
            };

            var source = new List<IDomainName>() { domain, domain2, sub };

            IDictionary<IDomainName, SubDomainName> subdomains = CompressionHelper.CreateSubDomain(source);

            Assert.AreEqual("domain.", subdomains[domain].Name);
            Assert.AreEqual("com.", subdomains[domain].Right.Name);
            Assert.IsNull(subdomains[domain].Right.Right);

            Assert.AreEqual("domain.", subdomains[domain2].Name);
            Assert.AreEqual("com.", subdomains[domain2].Right.Name);
            Assert.AreEqual("tld2.", subdomains[domain2].Right.Right.Name);
            Assert.IsNull(subdomains[domain2].Right.Right.Right);

            Assert.AreEqual("sub.", subdomains[sub].Name);
            Assert.AreEqual("domain.", subdomains[sub].Right.Name);
            Assert.AreEqual("com.", subdomains[sub].Right.Right.Name);
            Assert.IsNull(subdomains[sub].Right.Right.Right);

            Assert.AreEqual(subdomains[domain], subdomains[sub].Right);

        }

        [Test]
        public void TestCreateSubDomainBuggy() {

            DomainName domain = new DomainName() {
                Name = "domain.com"
            };

            var source = new List<IDomainName>() { domain };

            CompressionHelper.SanitanizeDomain(source);
                        IDictionary<IDomainName, SubDomainName> subdomains = CompressionHelper.CreateSubDomain(source);

            Assert.AreEqual("domain.", subdomains[domain].Name);
            Assert.AreEqual("com.", subdomains[domain].Right.Name);
            Assert.IsNull(subdomains[domain].Right.Right);

        }

        [Test]
        public void TestCreateSubDomainBuggy2() {

            DomainName domain = new DomainName() {
                Name = "dom..ain.com."
            };

            var source = new List<IDomainName>() { domain };

            CompressionHelper.SanitanizeDomain(source);
            IDictionary<IDomainName, SubDomainName> subdomains = CompressionHelper.CreateSubDomain(source);

            Assert.AreEqual("dom.", subdomains[domain].Name);
            Assert.AreEqual("ain.", subdomains[domain].Right.Name);
            Assert.AreEqual("com.", subdomains[domain].Right.Right.Name);

        }


        [Test]
        public void TestCreateSubDomain8() {

            string expected = "f8de81800001001200030003036170690a7261706964736861726503636f6d0000010001c00c00010001000003840004c37a8323c00c00010001000003840004c37a8324c00c00010001000003840004c37a8325c00c00010001000003840004c37a8326c00c00010001000003840004c37a8327c00c00010001000003840004c37a8328c00c00010001000003840004c37a8317c00c00010001000003840004c37a8318c00c00010001000003840004c37a8319c00c00010001000003840004c37a831ac00c00010001000003840004c37a831bc00c00010001000003840004c37a831cc00c00010001000003840004c37a831dc00c00010001000003840004c37a831ec00c00010001000003840004c37a831fc00c00010001000003840004c37a8320c00c00010001000003840004c37a8321c00c00010001000003840004c37a8322c01000020001000003840006036e7333c010c01000020001000003840006036e7331c010c01000020001000003840006036e7332c010c15000010001000003840004528127cdc16200010001000003840004c37a83fac1740001000100000000000450ef97cd";
            IMessage message = PacketHelper.Read(expected);


            var domains = new List<IDomainName>();
            CompressionHelper.CreateDomain(message, domains);
            IDictionary<IDomainName, SubDomainName> subdomains = CompressionHelper.CreateSubDomain(domains);

            SubDomainName api = subdomains[domains.ElementAt(0)];
            SubDomainName rapidshare = api.Right;
            SubDomainName com = rapidshare.Right;
            SubDomainName ns3 = subdomains[domains.ElementAt(4)];
            SubDomainName ns1 = subdomains[domains.ElementAt(5)];
            SubDomainName ns2 = subdomains[domains.ElementAt(6)];

            Assert.AreEqual(rapidshare, subdomains[domains.ElementAt(1)]);
            Assert.AreEqual(rapidshare, subdomains[domains.ElementAt(2)]);
            Assert.AreEqual(rapidshare, subdomains[domains.ElementAt(3)]);
            Assert.AreEqual(rapidshare, ns3.Right);
            Assert.AreEqual(rapidshare, ns1.Right);
            Assert.AreEqual(rapidshare, ns2.Right);
            Assert.AreEqual(rapidshare, api.Right);
            Assert.AreEqual(api, subdomains[domains.ElementAt(8)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(9)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(11)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(12)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(13)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(14)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(15)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(16)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(17)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(18)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(19)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(20)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(21)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(22)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(23)]);
            Assert.AreEqual(api, subdomains[domains.ElementAt(24)]);
            Assert.AreEqual(ns3, subdomains[domains.ElementAt(25)]);
            Assert.AreEqual(ns1, subdomains[domains.ElementAt(26)]);
            Assert.AreEqual(ns2, subdomains[domains.ElementAt(27)]);



        }
        #endregion

        #region RecurseSubDomain
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestRecusreSubDomainNull() {

            string domainName = CompressionHelper.FullDomain(null);

        }

        [Test]
        public void TestRecusreSubDomainLoop() {

            SubDomainName head = new SubDomainName() {
                Name = "head."
            };
            SubDomainName tail = new SubDomainName() {
                Name = "tail.",
                Right = head
            };

            head.Right = tail;
            string domainName = tail.FullDomain();
            Assert.AreEqual("tail.head.", domainName);

        }

        [Test]
        public void TestRecusreSubDomainLoop2() {

            SubDomainName head = new SubDomainName() {
                Name = "head."
            };
            SubDomainName body = new SubDomainName() {
                Name = "body.",
                Right = head
            };
            SubDomainName tail = new SubDomainName() {
                Name = "tail.",
                Right = body
            };

            head.Right = tail;
            string domainName = CompressionHelper.FullDomain(tail);
            Assert.AreEqual("tail.body.head.", domainName);

        }

        [Test]
        public void TestRecurseSubDomain() {

            DomainName domain = new DomainName() {
                Name = "domain.tld."
            };
            DomainName host = new DomainName() {
                Name = "host.domain.tld."
            };
            DomainName sub = new DomainName() {
                Name = "sub.domain.tld."
            };
            DomainName host1 = new DomainName() {
                Name = "host1.sub.domain.tld."
            };
            DomainName host2 = new DomainName() {
                Name = "host2.sub.domain.tld."
            };
            DomainName domain2 = new DomainName() {
                Name = "domain2.tld."
            };

            var source = new List<IDomainName>() { domain, host, sub, host1, host2, domain2 };

            IDictionary<IDomainName, SubDomainName> subdomains = CompressionHelper.CreateSubDomain(source);

            string domainName = subdomains[domain].FullDomain();
            string hostName = subdomains[host].FullDomain();
            string subName = subdomains[sub].FullDomain();
            string host1Name = subdomains[host1].FullDomain();
            string host2Name = subdomains[host2].FullDomain();
            string domain2Name = subdomains[domain2].FullDomain();

            Assert.AreEqual(domain.Name, domainName);
            Assert.AreEqual(host.Name, hostName);
            Assert.AreEqual(sub.Name, subName);
            Assert.AreEqual(host1.Name, host1Name);
            Assert.AreEqual(host2.Name, host2Name);
            Assert.AreEqual(domain2.Name, domain2Name);

        }

        #endregion

        #region SanitanizeDomain
        [Test]
        public void TestSanitanizeDomain1() {

            DomainName domain = new DomainName() {
                Name = "dom..ain.com."
            };
            var source = new List<IDomainName>() { domain };
            CompressionHelper.SanitanizeDomain(source);

            Assert.AreEqual("dom.ain.com.", domain.Name);

        }

        [Test]
        public void TestSanitanizeDomain2() {

            DomainName domain = new DomainName() {
                Name = "dom...........ain.com."
            };
            CompressionHelper.SanitanizeDomain(domain);

            Assert.AreEqual("dom.ain.com.", domain.Name);

        }

        [Test]
        public void TestSanitanizeDomain3() {

            DomainName domain = new DomainName() {
                Name = "ésoutch¦@#°#@§¬|¢´~.com."
            };
            CompressionHelper.SanitanizeDomain(domain);

            Assert.AreEqual("soutch.com.", domain.Name);

        }

        #endregion

    }
}

